Suppose you wish to tabulate ACS one-year 2019 data for estimates of total people by race and ethnicity, as provided in table B03002 by PSRC counties. You would use the following function call:
get_acs_recs(geography = 'county',
table.names = 'B03002',
years = 2019,
acs.type = 'acs1')## # A tibble: 105 × 11
## GEOID name state variable estimate moe label concept census_geography
## <chr> <chr> <chr> <chr> <dbl> <dbl> <chr> <chr> <chr>
## 1 53033 King Coun… Wash… B03002_… 2252782 NA Esti… HISPAN… County
## 2 53033 King Coun… Wash… B03002_… 2030140 NA Esti… HISPAN… County
## 3 53033 King Coun… Wash… B03002_… 1302544 3208 Esti… HISPAN… County
## 4 53033 King Coun… Wash… B03002_… 147822 4678 Esti… HISPAN… County
## 5 53033 King Coun… Wash… B03002_… 13321 1990 Esti… HISPAN… County
## 6 53033 King Coun… Wash… B03002_… 424590 7085 Esti… HISPAN… County
## 7 53033 King Coun… Wash… B03002_… 15702 1831 Esti… HISPAN… County
## 8 53033 King Coun… Wash… B03002_… 6574 3281 Esti… HISPAN… County
## 9 53033 King Coun… Wash… B03002_… 119587 8804 Esti… HISPAN… County
## 10 53033 King Coun… Wash… B03002_… 2639 1744 Esti… HISPAN… County
## # … with 95 more rows, and 2 more variables: acs_type <chr>, year <dbl>
By default, without specifying any counties, the jurisdictions
returned will be King, Kitsap, Pierce, and Snohomish Counties. Use
?get_acs_recs() for other default values implemented in
this function.
To retrieve non-PSRC counties or a subset of the default counties,
use the counties argument and provide a vector of counties
(e.g. counties = c("King", "Thurston")). Do not use the
fips argument as that is reserved for MSA or place
geographies.
The get_decennial_recs() to generate Decennial Census
tables operates similarly to the get_acs_recs(). If you
wanted to retrieve housing units and total population by MSA, you would
call the following:
get_decennial_recs(geography = 'msa',
table_codes = c("H001", "P001"),
years = c(2010),
fips = c('42660', "28420"))## # A tibble: 4 × 7
## GEOID NAME variable value year label concept
## <chr> <chr> <chr> <dbl> <dbl> <chr> <chr>
## 1 28420 Kennewick-Pasco-Richland, WA Metro … H001001 9.30e4 2010 Total HOUSIN…
## 2 42660 Seattle-Tacoma-Bellevue, WA Metro A… H001001 1.46e6 2010 Total HOUSIN…
## 3 28420 Kennewick-Pasco-Richland, WA Metro … P001001 2.53e5 2010 Total TOTAL …
## 4 42660 Seattle-Tacoma-Bellevue, WA Metro A… P001001 3.44e6 2010 Total TOTAL …
Note: the table names are padded with 0s, so you call “H001” as opposed to “H1” as you would in Elmer. Only SF1 tables are currently implemented.
Let’s say you want to create a map of the tracts in the region for
one variable. You can use the function create_tract_map().
Here’s an example, mapping non-Hispanic Black or African American
population alone by tract:
library(sf)
library(dplyr)
tract.big.tbl <- get_acs_recs(geography ='tract',
table.names = 'B03002',
years = 2019)
tract.tbl <- tract.big.tbl %>%
filter(label=='Estimate!!Total:!!Not Hispanic or Latino:!!Black or African American alone')
tract.url <- "https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson"
#'
tract.lyr<-st_read(tract.url)## Reading layer `OGRGeoJSON' from data source
## `https://services6.arcgis.com/GWxg6t7KXELn1thE/arcgis/rest/services/tract2010_nowater/FeatureServer/0/query?where=0=0&outFields=*&f=pgeojson'
## using driver `GeoJSON'
## Simple feature collection with 773 features and 21 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -123.0234 ymin: 46.72799 xmax: -120.9062 ymax: 48.29924
## Geodetic CRS: WGS 84
create_tract_map(tract.tbl,
tract.lyr,
map.title='Black, non-Hispanic Population',
map.title.position='topleft',
legend.title='Black, Non-Hispanic Population',
legend.subtitle='by Census Tract')